package com.cody;

import java.util.concurrent.CountDownLatch;

public class Exercise2 {
	
	private static volatile int value;
    private static CountDownLatch countDownLatch = new CountDownLatch(10000);
    public static void main(String[] args) {
        for (int i=0;i<10000;i++){
            new Thread(){
                @Override
                public void run() {
                    increment();
                    countDownLatch.countDown();
                }
            } .start();
 
        }
        try {
			countDownLatch.await();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        System.out.println(getValue());
    }
 
    public synchronized static int increment(){
        return value ++;
    }
 
    public static int getValue(){
        return value;
    }

}
